#include <iostream>
#include <pthread.h>
#include <unistd.h>

int g_val = 0;//共享资源

using namespace std;


void* thread1(void* args)
{
    while(true)
    {
        sleep(1);
        cout << "t1 thread..." << getpid() << " &g_val: " <<  &g_val << " g_val: "<< g_val <<endl;
    }
}

void* thread2(void* args)
{
    while(true)
    {
        sleep(1);
        cout << "t2 thread..." << getpid() << " &g_val: " <<  &g_val << " g_val: "<< g_val++ << endl;
    }
}

int main()
{
    pthread_t t1, t2, t3;

    pthread_create(&t1, nullptr, thread1, nullptr);
    pthread_create(&t2, nullptr, thread2, nullptr);

    while(true)
    {
        sleep(1);
        //主线程
        cout << "main thread..." <<  getpid() << " &g_val: " <<  &g_val << " g_val: "<< g_val << endl;
    }
    
    return 0;
}